package cn.com.bluemoon.daps.api.sys;

import cn.com.bluemoon.daps.api.sys.factory.RemoteSystemInfoServiceFallbackFactory;
import cn.com.bluemoon.daps.common.annotation.FcApiFor;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.enums.BmStatus;
import cn.com.bluemoon.daps.common.enums.DatabaseType;
import cn.com.bluemoon.daps.common.enums.SystemType;
import cn.com.bluemoon.daps.system.dto.SystemInfoDto;
import cn.com.bluemoon.daps.system.entity.DapSystemInfo;
import cn.com.bluemoon.daps.system.entity.DapSystemLeader;
import cn.com.bluemoon.daps.system.vo.SimpleSysInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Optional;

/**
 * @author Jarod.Kong
 */
@FeignClient(value = DapsApiSystem.SERVICE, fallbackFactory = RemoteSystemInfoServiceFallbackFactory.class)
@RequestMapping(DapsApiSystem.BASE_URI + DapsApiSystem.API_SYSINFO)
@ApiIgnore
public interface RemoteSystemInfoService {

    @PostMapping("/page")
    @ApiOperation("获取系统稽核列表数据")
    Page<SystemInfoDto> getSysInfoPage(@RequestParam("current") Long current,
                                       @RequestParam("pageSize") Long pageSize,
                                       @RequestParam(value = "keyword", required = false) String keyword,
                                       @RequestParam("bmStatus") BmStatus bmStatus);

    @GetMapping("/{id}")
    ResultBean<DapSystemInfo> getSystemInfo(@PathVariable("id") String id);

    @PostMapping("/getSystemInfoList")
    ResultBean<List<DapSystemInfo>> getSystemInfoList(@RequestParam(value = "ids", required = false) String ids);


    @ApiOperation("获取系统信息")
    @GetMapping("/get")
    @Deprecated
    Optional<DapSystemInfo> getById(@RequestParam("id") String sysId);

    @PutMapping("/auditStatus")
    ResultBean<Boolean> updateAuditStatusById(@RequestParam("status") Integer auditStatus,
                                              @RequestParam(value = "auditResultId", required = false, defaultValue = "") String auditResultId,
                                              @RequestParam("updateAuditTime") boolean updateAuditTime,
                                              @RequestParam("sysId") String systemId);

    /**
     * 元数据调用
     */
    @PostMapping("/list")
    @FcApiFor(team = "数据资产团队")
    ResultBean<List<DapSystemInfo>> getSysInfos(@RequestParam(value = "name", required = false) String name);

    /**
     * 根据员工号+用户类型获取相关系统信息
     * 用户类型对应系统人员列表：1 产品负责人、2技术负责人、3业务负责人
     * {@link DapSystemLeader#getProId()}
     * {@link DapSystemLeader#getTecId()}
     * {@link DapSystemLeader#getBusId()}
     *
     * @param userId   用户工号
     * @param userType 用户类型对应系统人员列表：1 产品负责人、2技术负责人、3业务负责人，非必填，默认为2
     * @return 根据员工号+用户类型相关系统信息
     */
    @GetMapping("/user/sysInfo")
    @FcApiFor(team = {"IT中心/技术研发部/供应链研发团队/SCM开发组", "数据资产团队"})
    ResultBean<List<SimpleSysInfoVo>> getSystemInfosByUserIdAndType(@RequestParam(value = "userId") String userId,
                                                                    @RequestParam(value = "userType", required = false, defaultValue = "2") Integer userType);

    /**
     * 根据指定数据库类型获取简易系统信息列表
     * 不是符合{@link DatabaseType#getCode}的返回code=500
     *
     * @param dbType 1 mysql, 2 pgsql, 3 hive,... etc.
     * @return result
     * @see DatabaseType
     * @see SystemType
     */
    @GetMapping("/system/dbType")
    @FcApiFor(team = {"数据资产团队"})
    public ResultBean<List<SimpleSysInfoVo>> listByDbType(@RequestParam(value = "dbType") Integer dbType);

    @GetMapping("/system/info")
    @FcApiFor(team = "数据资产团队")
    ResultBean<DapSystemInfo> getSysInfo(@RequestParam(value = "name") String name);

}
